<?php
require ABSPATH . "/wp-admin/includes/plugin.php";
require ABSPATH . "/wp-admin/includes/template.php";

if (!function_exists("wdstar_theme_setup")) {
    /**
     * 安装主题
     * @author ATOM STUDIO
     * @link http://www.fennubird.cn
     */
    function wdstar_theme_setup() {
        if (!is_plugin_active('woocommerce/woocommerce.php') && is_admin()) {
           add_settings_error('woocommerce-required','plugin-required','主题需要安装<a href="/wp-admin/plugin-install.php?s=woocommerce&tab=search&type=term">Woocommerce</a>插件','error');
           settings_errors('woocommerce-required','');
        }
        /*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Twenty Nineteen, use a find and replace
		 * to change 'wdstar' to the name of your theme in all the template files.
		 */
        load_theme_textdomain( 'wdstar', get_template_directory() . '/languages' );

        /*
         * Let WordPress manage the document title.
         * By adding theme support, we declare that this theme does not use a
         * hard-coded <title> tag in the document head, and expect WordPress to
         * provide it for us.
         */
        add_theme_support( 'title-tag' );

        /*
         * Enable support for Post Thumbnails on posts and pages.
         *
         * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
         */
        add_theme_support( 'post-thumbnails' );

        set_post_thumbnail_size( 290, 290 );

        // This theme uses wp_nav_menu() in 3 locations.
        register_nav_menus(
            array(
                'main' => __( 'Main', 'wdstar' ),
                'footer' => __( 'Footer Menu', 'wdstar' ),
                'social' => __( 'Social Links Menu', 'wdstar' ),
            )
        );

        /*
         * Switch default core markup for search form, comment form, and comments
         * to output valid HTML5.
         */
        add_theme_support(
            'html5',
            array(
                'search-form',
                'comment-form',
                'comment-list',
                'gallery',
                'caption',
            )
        );

        /**
         * Add support for core custom logo.
         *
         * @link https://codex.wordpress.org/Theme_Logo
         */
        add_theme_support(
            'custom-logo',
            array(
                'height'      => 80,
                'width'       => 160,
                'flex-width'  => false,
                'flex-height' => false,
            )
        );

        // Add theme support for selective refresh for widgets.
        add_theme_support( 'customize-selective-refresh-widgets' );

        // Add support for Block Styles.
        add_theme_support( 'wp-block-styles' );

        // Add support for full and wide align images.
        add_theme_support( 'align-wide' );

        // Add support for editor styles.
        add_theme_support( 'editor-styles' );

        // Enqueue editor styles.
        add_editor_style( 'style-editor.css' );

        // Add custom editor font sizes.
        add_theme_support(
            'editor-font-sizes',
            array(
                array(
                    'name'      => __( 'Small', 'wdstar' ),
                    'shortName' => __( 'S', 'wdstar' ),
                    'size'      => 19.5,
                    'slug'      => 'small',
                ),
                array(
                    'name'      => __( 'Normal', 'wdstar' ),
                    'shortName' => __( 'M', 'wdstar' ),
                    'size'      => 22,
                    'slug'      => 'normal',
                ),
                array(
                    'name'      => __( 'Large', 'wdstar' ),
                    'shortName' => __( 'L', 'wdstar' ),
                    'size'      => 36.5,
                    'slug'      => 'large',
                ),
                array(
                    'name'      => __( 'Huge', 'wdstar' ),
                    'shortName' => __( 'XL', 'wdstar' ),
                    'size'      => 49.5,
                    'slug'      => 'huge',
                ),
            )
        );

        // Editor color palette.
        add_theme_support(
            'editor-color-palette',
            array(
                array(
                    'name'  => __( 'Primary', 'wdstar' ),
                    'slug'  => 'primary',
                    'color' => "blue",
                ),
                array(
                    'name'  => __( 'Secondary', 'wdstar' ),
                    'slug'  => 'secondary',
                    'color' => "grey",
                ),
                array(
                    'name'  => __( 'Dark Gray', 'wdstar' ),
                    'slug'  => 'dark-gray',
                    'color' => '#111',
                ),
                array(
                    'name'  => __( 'Light Gray', 'wdstar' ),
                    'slug'  => 'light-gray',
                    'color' => '#767676',
                ),
                array(
                    'name'  => __( 'White', 'wdstar' ),
                    'slug'  => 'white',
                    'color' => '#FFF',
                ),
            )
        );

        // Add support for responsive embedded content.
        add_theme_support( 'responsive-embeds' );

        add_image_size('category',400,300);
        add_image_size('image-box',600,600);
        //隐藏admin bar
        show_admin_bar( false );
        /*自定义WooCommerce模板*/
	    add_theme_support( 'woocommerce',[
	            'thumbnail_image_width' => 300,
        ] );
        add_theme_support( 'wc-product-gallery-zoom' );
        add_theme_support( 'wc-product-gallery-lightbox' );
        add_theme_support( 'wc-product-gallery-slider' );
    }

    add_action("after_setup_theme", "wdstar_theme_setup");
}


/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function wdstar_widgets_init() {

    register_sidebar(
        array(
            'name'          => __( 'Footer column one', 'wdstar' ),
            'id'            => 'footer-col-1',
            'description'   => __( 'Add widgets here to appear in your footer column one.', 'wdstar' ),
            'before_widget' => false,
            'after_widget'  => false,
            'before_title'  => '<h2 class="footer-title">',
            'after_title'   => '</h2>',
        )
    );
    register_sidebar(
        array(
            'name'          => __( 'Footer column two', 'wdstar' ),
            'id'            => 'footer-col-2',
            'description'   => __( 'Add widgets here to appear in your footer column two.', 'wdstar' ),
            'before_widget' => false,
            'after_widget'  => false,
            'before_title'  => '<h2 class="footer-title">',
            'after_title'   => '</h2>',
        )
    );
	register_sidebar(
		array(
			'name'          => __( 'Footer column three', 'wdstar' ),
			'id'            => 'footer-col-3',
			'description'   => __( 'Add widgets here to appear in your footer column three.', 'wdstar' ),
			'before_widget' => false,
			'after_widget'  => false,
			'before_title'  => '<h2 class="footer-title">',
			'after_title'   => '</h2>',
		)
	);


}
add_action( 'widgets_init', 'wdstar_widgets_init' );

/**
 * Enqueue scripts and styles.
 */
function wdstar_scripts() {

    wp_enqueue_style( 'wdstar-main-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
    wp_enqueue_style( 'bootstrap', get_theme_file_uri("/assets/css/bootstrap.min.css"), array(), '4.3' );
    wp_enqueue_style( 'font-awesome', get_theme_file_uri("/assets/css/fontawesome.min.css"), array(), '4.7' );
    wp_enqueue_style( 'animate', get_theme_file_uri("/assets/css/animate.min.css"), array(), '4.7' );
    wp_enqueue_script( 'jquery3', get_theme_file_uri("/assets/js/jquery.min.js"), array(), '3.4' );
    wp_enqueue_script( 'wow', get_theme_file_uri("/assets/js/wow.js"), array(), '3.4' );
	wp_enqueue_script('popper.js','https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js',array(),'1.15');
	wp_enqueue_script( 'bootstrap', get_theme_file_uri("/assets/js/bootstrap.min.js"), array(), '4.3' );
	if (is_page("service")) {
        wp_enqueue_script( 'waypoints', get_theme_file_uri("/assets/js/jquery.waypoints.min.js"), array(), '1' );
	    wp_enqueue_script( 'countup', get_theme_file_uri("/assets/js/jquery.countup.min.js"), array(), '1' );
    }

    if (!is_admin() && !is_woocommerce()) {
        wp_deregister_script('jquery');
        wp_deregister_script('jquery-migrate');
    }
    if ( !is_woocommerce() && (is_home()|| is_page() || is_singular() || is_single()) ) {
        wp_enqueue_style('owl-carousel',get_theme_file_uri('assets/css/owl.carousel.min.css'),array(),'2.0');
        wp_enqueue_style('owl-carousel.theme',get_theme_file_uri('assets/css/owl.theme.default.css'),array(),'2.0');
        wp_enqueue_script('owl-carousel.main',get_theme_file_uri('assets/js/owl.carousel.min.js'),array(),'2.0');
    }
	wp_enqueue_script('main',get_theme_file_uri('assets/js/main.js'),array(), '1.0');
    if (is_woocommerce()) {
        wp_dequeue_script('wow');
        wp_dequeue_style('animate');
        wp_enqueue_style('product',get_theme_file_uri('assets/css/product.css'),[],'1.0');
    }
}
add_action( 'wp_enqueue_scripts', 'wdstar_scripts' );


/**
 * Require Custom Walker
 */
require "inc/Atom_nav.php";

require "inc/custom-func.php";

/*
 * 加入Redux后台框架
 * Copyright © author
 * Link: http://demo.fennubird.cn/guides/advanced/embedding-redux.html
 * */


if ( !class_exists( 'ReduxFramework' ) && file_exists( dirname( __FILE__ ) . '/framework/ReduxCore/framework.php' ) ) {
    require_once( dirname( __FILE__ ) . '/framework/ReduxCore/framework.php' );
}
if ( !isset( $redux_demo ) && file_exists( dirname( __FILE__ ) . '/framework/sample/sample-config.php' ) ) {
    require_once( dirname( __FILE__ ) . '/framework/sample/sample-config.php' );
}